﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KNXObjects
{
    public class S8Object : GenericObjectBase<int>
    {
        #region ObjectBase Implementations

        public override string DataPointEISName
        {
            get { return "EIS14"; }
        }

        public override string DataPointID
        {
            get { return "6.xxx"; }
        }

        public override string ToString()
        {
            return Value.ToString();
        }

        public override int Value
        {
            get
            {
                return base.Value;
            }
            set
            {
                if (value > 127 || value < -128)
                    throw new ApplicationException("S8ObjectValue: value must be between -128 and 127. Val : " + value);
                base.Value = value;
            }
        }

        public override void SetValue(string value)
        {
            int val;
            if (!int.TryParse(value, out val))
                throw new ApplicationException(string.Format("Format error, cannot convert value {0} to INT32", value));

            Value = val;
        }

        #endregion

        #region ctor

        public S8Object(string id, string address, string name, string flags)
            : base(id, address, name, flags)
        {
        }

        public S8Object(string value)
        {
            SetValue(value);
        }
        #endregion
    }
}
